﻿@using Microsoft.AspNetCore.Html
@using System.Text;
@model List<WebMvc.Areas.Sys.Models.Menu>

<li><a asp-area="" asp-controller="Home" asp-action="Index" target="_blank"><i class="fa fa-link"></i> 前台首页</a></li>


    @{var firstMenus = Model.FindAll(w => w.ParentId == 0);}
    @foreach (var fm in firstMenus)
    {
        var isActive = true;
        <li class="@(isActive ? "active treeview" : "treeview")">
            <a href="#">
                <i class="@fm.Icon"></i> <span>@fm.Name</span>
                <span class="pull-right-container">
                    <i class="fa fa-angle-left pull-right"></i>
                </span>
            </a>
            <ul class="treeview-menu">
                @{ var secMenus = Model.FindAll(w => w.ParentId == fm.Id);}
                @foreach (var sm in secMenus)
                {
                    var isActive1 = ViewBag.CurrentMenu == sm.Code;
                    <li class="@(isActive1 ? "active" : "")"><a href="@sm.Url"><i class="@sm.Icon"></i><span>@sm.Name</span></a></li>
                }
            </ul>
        </li>
    }
        

<li><a asp-area="Sys" asp-controller="Home" asp-action="About"><i class="fa fa-link"></i> 关于</a></li>


@*@functions
{
    public IHtmlContent GetMenus(List<DEL.Sys.Menu> menus, int parentid)
    {
        StringBuilder sb = new StringBuilder();
        MenuParent(sb, menus, parentid);
        return new HtmlString(sb.ToString());
    }

    public void MenuParent(StringBuilder sb, List<DEL.Sys.Menu> menus, int parentid)
    {

        List<DEL.Sys.Menu> menuParent = menus.FindAll(t => t.ParentId == parentid);
        foreach (var node in menuParent)
        {
            sb.Append("<li class='treeview'>");
            sb.Append("<a href='" + node.Url + "'>");
            sb.Append("<i class='" + node.Icon + "'></i> <span>" + node.Name + "</span>");
            sb.Append("<span class='pull-right-container'>");
            sb.Append("<i class='fa fa-angle-left pull-right'></i>");
            sb.Append("</span>");
            sb.Append("</a>");
            MenuSun(sb, menus, node.Id);
            sb.Append("</li>");
        }
    }

    public void MenuSun(StringBuilder sb, List<DEL.Sys.Menu> menus, int id)
    {
        List<DEL.Sys.Menu> menuSun = menus.FindAll(t => t.ParentId == id);

        if (menuSun.Count > 0)
        {
            sb.Append("<ul class='treeview-menu'>");
            foreach (var node in menuSun)
            {
                if (menus.FindAll(t => t.ParentId == node.Id).Count > 0)
                {
                    MenuParent(sb, menus, node.Id);
                }
                else
                {
                    sb.Append("<li><a href=" + node.Url + "><i class='" + node.Icon + "'></i>" + node.Name + "</a></li>");
                }
            }
            sb.Append("</ul>");
        }
        else
        {
            return;
        }
    }
}

@GetMenus(Model, 0)*@